<template>
	<view>
		<topbar title="合作伙伴" jt_c="2" background="background:#222222;color:#fff;"></topbar>
		<view class="content dis_f_co_c_c">
			<image class="top_img" src="../../static/mine/hhr.png" mode=""></image>
			<view class="dis_f_sb_c" style="width: 100%;margin-bottom: 36rpx;">
				<view class="line"></view>
				<view class="text">此公告牌由合伙人设置发布</view>
				<view class="line"></view>
			</view>
			<view class="cw_dl dis_f_co" v-if="ishehuo == 0">
				<view v-if="list == ''" style="margin-bottom: 40rpx;width: 100%;" class="dis_f_c_c">该地区暂无代理</view>
				<view class="dis_f_l_c" v-else v-for="(item,index) in list"
					style="border-bottom: 2rpx solid #EEE;padding-bottom: 24rpx;margin-bottom: 22rpx;">
					<image class="tx" src="http://jk85472adeg.htjy668.cn\uploads\admin\admin_thumb\20180104\79811855a6c06de53047471c4ff82a36.jpg" mode=""></image>
					<view class="dis_f_co" style="width: 100%;">
						<view class="dis_f_co">
							<view class="dis_f">
								<view class="title">{{item.province +  item.city  + item.area}}</view>
								<view class="top_bq">
									<image src="../../static/mine/top_bq.png" mode="aspectFit"></image>
								</view>
							</view>
							<view class="b_text dis_f_sb_c">
								<view>{{item.user_name}}</view>
								<view>代理价格：{{item.money}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="dis_f_r_c">
					<view class="qt_btn dis_f_c_c" @click="shows = true">其他地区</view>
					<view class="cl_btn dis_f_c_c" @click="check">我要成为代理</view>
					<u-picker mode="region" v-model="shows" @confirm="confirm" :params="params"></u-picker>
				</view>
				<u-popup v-model="show" mode="center" width="500" height="100" border-radius="20">
					<view class="dis_f_sb_c tc_pay">
						<view class="dis_f_l_c" @click="pay">
							<image src="../../static/mine/vx.png" mode=""></image>
							<view>微信支付</view>
						</view>
						<view class="dis_f_l_c" @click="pay2">
							<image src="../../static/mine/zfb.png" mode=""></image>
							<view>支付宝支付</view>
						</view>
					</view>
				</u-popup>
			</view>
			
			
			<view class="cw_dl dis_f_co" v-else>
			
				<view class="dis_f_l_c"
					style="border-bottom: 2rpx solid #EEE;padding-bottom: 24rpx;margin-bottom: 22rpx;">
					<image class="tx" :src="user.avatar" mode=""></image>
					<view>{{user.name}}</view>
					<view>{{user.hehuorenren}}</view>
				</view>
			
			</view>
			<view class="b_box dis_f_c_c">
				注:区县合伙人享受整个区县的会员1%收益、城市合伙人享受整个城市的会员1%收益、省级合伙人享受整个省会员的1%收益
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shows: false,
				params: {
					province: true,
					city: true,
					area: true,
				},
				list:[],
				address:'',
				city:'',
				show:false,
				ishehuo:0,
				user:[]
			};
		},
		onLoad(){
			this.get_location();
		},
		onShow() {
			var that = this
			// uni.setStorageSync('',that.address)
			console.log(uni.getStorageSync('district'))
			this.$.ajax(1, 'post', 'city/get_area_image', {
				uid:uni.getStorageSync('uid'),
				token:uni.getStorageSync('token'),
				// province:that.address.province.label,
				// city:that.address.city.label,
				area:uni.getStorageSync('district'),
			}, (res) => {
				this.ishehuo = res.hehuoren
				this.user = res.user
				console.log(res)
				
				
				
			})
			
		},
		methods: {
			check(){
				if(this.address == ''){
					this.$.ti_shi('请选择开通的地区')
					return;
				}else{
					this.$.ti_shi('请联系客服')
					return;
					this.show = true
				}
			},
			pay2(){
				var that = this
					this.$.ajax(1, 'post', 'index/checktokens', {
							uid:uni.getStorageSync('uid'),
							token:uni.getStorageSync('token')
						}, (res) => {
							console.log(res)
							if(res.code == 9){
								this.$.ti_shi('token已过期，请重新登陆')
							uni.clearStorageSync()
								setTimeout( () => {
									uni.navigateTo({
										url:'/pages/login/login'
									})
								}, 1000)
							return;
							}
							else{
									this.$.ajax(1, 'post', 'alipay/cityalipay', {
									uid:uni.getStorageSync('uid'),
									token:uni.getStorageSync('token'),
									province:that.address.province.label,
									city:that.address.city.label,
									area:that.address.area.label,
								}, (res) => {
									console.log(res)
									if(res.code == 1) {
										uni.requestPayment({
											provider: 'alipay',
											orderInfo: res.data,
											success: function (res) {
												console.log(res);
											},
											fail: function (err) {
												console.log('fail:' + JSON.stringify(err));
											}
										});
									}else{
										this.$.ti_shi(res.msg)
									}
									
									
									
								})
							}
						})
			},
			pay(){
				
				this.$.ajax(1, 'post', 'index/checktokens', {
						uid:uni.getStorageSync('uid'),
						token:uni.getStorageSync('token')
					}, (res) => {
						console.log(res)
						if(res.code == 9){
							this.$.ti_shi('token已过期，请重新登陆')
						uni.clearStorageSync()
							setTimeout( () => {
								uni.navigateTo({
									url:'/pages/login/login'
								})
							}, 1000)
						return;
						}
						else{
								this.$.ajax(1, 'post', 'wxpay/wxpaycity', {
								uid:uni.getStorageSync('uid'),
								token:uni.getStorageSync('token'),
								
							}, (res) => {
								console.log(res)
								if(res.code == 1){
									// console.log(res.data.timestamp)
								uni.requestPayment({
									provider: 'wxpay',
									orderInfo: {
													"appid": res.data.appid,
													"noncestr": res.data.noncestr,
													"package": "Sign=WXPay",
													"partnerid": res.data.partnerid,
													"prepayid": res.data.prepayid,
													"timestamp": res.data.timestamp,
													"sign": res.data.sign
												},
									success: function (res) {
										console.log(res);
									},
									fail: function (err) {
										console.log('fail:' + JSON.stringify(err));
									}
								});
								}else{
									this.$.ti_shi(res.msg)
								}
								
							})
						}
					})
				
			},
			// 获取当前地理位置
			get_location() {
				let that = this
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					success: function(res) {
						
						that.$.ajax(1,'POST','/city/get_city_list',{
							province: res.address.province,
							city:res.address.city,
							area:res.address.district,
							
						},(res)=>{
							that.list = res.data
						})
					}
				});
			},
			get_dl(){
				this.$.ajax(1,'POST','/city/get_city_list',{
					province:this.address.province.label,
					city:this.address.city.label,
					area:this.address.area.label,
					
				},(res)=>{
					this.list = res.data
				})
			},
			confirm(params) {
				console.log(params.province.label + params.city.label + params.area.label)
				
				this.address = params
				console.log(params.area.label)
				// console.log(this.address.area.label)
				this.get_dl()
			}
		}
	}
</script>

<style lang="scss">
	.tc_pay{
		width: 100%;
		padding: 20rpx;
		
		image{
			width: 60rpx;
			height: 60rpx;
			margin-right: 20rpx;
		}
	}
	.tg_bz {
		position: fixed;
		z-index: 999;
		font-size: 22rpx;
		line-height: 32rpx;
		top: calc(var(--status-bar-height) + 30rpx);
		right: 48rpx;
		color: #fff;
	
		image {
			width: 34rpx;
			height: 34rpx;
			margin-right: 6rpx;
		}
	
	}
	
	.content {
		padding: calc(var(--status-bar-height) + 124rpx) 24rpx 0 24rpx;
		width: 100%;
		.b_box{
			width: 100%;
			padding: 36rpx 24rpx;
			background-color: #fff;
			border-radius: 20rpx;
			font-size: 22rpx;
			margin-bottom: 20rpx;
			line-height: 32rpx;
			color: #E23C63;
		}
		.cl_btn {
			width: 262rpx;
			height: 58rpx;
			color: #fff;
			background-color: #E23C63;
			border-radius: 30rpx;
			font-size: 22rpx;
			line-height: 32rpx;
		}

		.popup {
			padding: 60rpx 38rpx 60rpx 34rpx;
		}

		.qt_btn {
			width: 200rpx;
			height: 58rpx;
			color: #777;
			border: 2rpx solid #777777;
			border-radius: 30rpx;
			font-size: 22rpx;
			line-height: 32rpx;
			margin-right: 24rpx;
		}

		.top_img {
			width: 100%;
			height: 702rpx;
			margin-bottom: 48rpx;
		}

		.line {
			height: 2rpx;
			width: 190rpx;
			background-color: #E23C63;
		}

		.text {
			font-size: 22rpx;
			color: #E23C63;
			line-height: 42rpx;
		}

		.cw_dl {
			width: 100%;
			padding: 36rpx 24rpx;
			background-color: #fff;
			border-radius: 20rpx;
			box-shadow: 0rpx 6rpx 24rpx rgba(34, 34, 34, 0.05);
			margin-bottom: 24rpx;
			.tx {
				width: 76rpx;
				height: 76rpx;
				border-radius: 50%;
				margin-right: 24rpx;
			}

			.title {
				font-size: 28rpx;
				line-height: 40rpx;
				margin-bottom: 6rpx;
				color: #222222;
				margin-right: 10rpx;
			}

			.top_bq {
				width: 66rpx;
				height: 24rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.b_text {
				font-size: 22rpx;
				line-height: 32rpx;
				color: #BBB;
			}
		}
	}
</style>
